(function(){"use strict";BX.namespace("BX.Landing.UI.Form");BX.Landing.UI.Form.DynamicCardsForm=function(e){BX.Landing.UI.Form.BaseForm.apply(this,arguments);this.type=e.type;this.code=e.code;this.presets=e.presets;this.sync=e.sync;this.forms=e.forms;this.id=this.code.replace(".","")+"-"+BX.Landing.Utils.random();this.onSourceChangeHandler=e.onSourceChange;this.dynamicParams=e.dynamicParams;this.settingFieldsSelectors=["source","pagesCount","detailPage","useSef"];this.sourceField=this.createSourceField();this.pagesField=this.createPagesField();this.addField(this.sourceField);this.addField(this.pagesField);this.detailPageGroup=this.createFieldsGroup([this.createLinkField()]);this.addCard(this.detailPageGroup)};BX.Landing.UI.Form.DynamicCardsForm.prototype={constructor:BX.Landing.UI.Form.DynamicCardsForm,__proto__:BX.Landing.UI.Form.BaseForm.prototype,getSources:function(){return BX.Landing.Main.getInstance().options.sources},getSourceItems:function(){return this.getSources().map(function(e){return{name:e.name,value:e.id,url:e.url?e.url.filter:"",filter:e.filter,sort:{items:e.sort.map(function(e){return{name:e.name,value:e.id}})},settings:e.settings}})},createSourceField:function(){var e=this.getSourceItems();var i={source:e[0].value,filter:e[0].filter};if(BX.type.isPlainObject(this.dynamicParams)&&BX.type.isPlainObject(this.dynamicParams.settings)&&BX.type.isPlainObject(this.dynamicParams.settings.source)){i.source=this.dynamicParams.settings.source.source;i.filter=this.dynamicParams.settings.source.filter;i.sort=this.dynamicParams.settings.source.sort}return new BX.Landing.UI.Field.SourceField({selector:"source",title:BX.Landing.Loc.getMessage("LANDING_CARDS__SOURCE_FIELD_TITLE"),items:e,value:i,onValueChange:function(e){var i=e.getValue();var t=this.getSources().find(function(e){return e.id===i.source});setTimeout(function(){if(!this.sourceField.isDetailPageAllowed()){BX.style(this.detailPageGroup.layout,"display","none")}else{BX.style(this.detailPageGroup.layout,"display",null)}this.onSourceChangeHandler(t)}.bind(this),0)}.bind(this)})},createPagesField:function(){return new BX.Landing.UI.Field.Pages({selector:"pagesCount",title:BX.Landing.Loc.getMessage("LANDING_CARDS__PAGES_FIELD_TITLE"),value:this.dynamicParams.settings.pagesCount})},createLinkField:function(){var e={text:"",href:""};if(BX.type.isPlainObject(this.dynamicParams)&&BX.type.isPlainObject(this.dynamicParams.settings)&&BX.type.isPlainObject(this.dynamicParams.settings.detailPage)){e=this.dynamicParams.settings.detailPage}return new BX.Landing.UI.Field.Link({selector:"detailPage",title:BX.Landing.Loc.getMessage("LANDING_CARDS__DETAIL_PAGE_FIELD_TITLE"),textOnly:true,disableCustomURL:true,disableBlocks:true,disallowType:true,allowedTypes:[BX.Landing.UI.Field.LinkURL.TYPE_PAGE],detailPageMode:true,sourceField:this.fields.find(function(e){return e.selector==="source"}),options:{siteId:BX.Landing.Main.getInstance().options.site_id,landingId:BX.Landing.Main.getInstance().id,filter:{"=TYPE":BX.Landing.Main.getInstance().options.params.type}},content:e})},createUseSefField:function(){return new BX.Landing.UI.Field.Checkbox({selector:"useSef",multiple:false,items:[{name:BX.Landing.Loc.getMessage("LANDING_CARDS__DETAIL_PAGE_USE_SEF"),value:true,checked:true}]})},createFieldsGroup:function(e){return new BX.Landing.UI.Card.DynamicFieldsGroup({items:e})},isReference:function(e){var i=this.getSources();if(BX.type.isArray(i)){return i.some(function(i){if(BX.type.isArray(i.references)){return i.references.some(function(i){return i.id===e})}return false})}return false},serialize:function(){var e=this.sourceField.isDetailPageAllowed();return this.fields.reduce(function(i,t){if(t.selector==="detailPage"&&!e){return i}var s=t.getValue();if(this.settingFieldsSelectors.includes(t.selector)){if(t.selector==="source"){i.source=s.source}i.settings[t.selector]=s}else if(s==="@hide"||BX.type.isPlainObject(s)&&s.id==="@hide"){i.references[t.selector]="@hide";if(BX.hasClass(t.layout,"landing-ui-field-dynamic-dropdown")){i.stubs[t.selector]=""}else if(BX.hasClass(t.layout,"landing-ui-field-dynamic-image")){i.stubs[t.selector]={id:-1,src:"",alt:""}}}else{if(this.isReference(s)||BX.type.isPlainObject(s)&&BX.type.isString(s.id)){if(this.isReference(s)){i.references[t.selector]={id:s}}else{i.references[t.selector]=s}}else{i.stubs[t.selector]=s}}return i}.bind(this),{settings:{},references:{},stubs:{}})}}})();
//# sourceMappingURL=dynamic_cards_form.map.js